package com.team.arms.political.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.team.arms.common.ry.core.controller.BaseController;
import com.team.arms.common.ry.core.domain.AjaxResult;
import com.team.arms.political.domain.PoliReviewInfo;
import com.team.arms.political.domain.vo.Policenvo;
import com.team.arms.political.mapper.PoliReviewInfoMapper;
import com.team.arms.political.service.PoliReviewInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @Author huazige
 * @Date 2022/4/29 22:09
 * @Version 1.0
 */
@RequestMapping("/politicenter")
@RestController
@CrossOrigin
@Api(tags = "政治考核-政审中,政审不合格")
public class Political_center extends BaseController {


    @Autowired
    PoliReviewInfoService poliReviewInfoService;
    @Resource
    PoliReviewInfoMapper poliReviewInfoMapper;


    /**
     * 查询所有政审中的信息
     */
    @ApiOperation("获取所有政审中信息")
//    @Log(title = "政审信息", businessType = BusinessType.)
    @GetMapping(value = "/getpol")
    public AjaxResult selectpltc() {
        String poliCarefulState="政审中";
        List<Policenvo> list = poliReviewInfoMapper.selectall(poliCarefulState);
//
        if (list!=null){
            return AjaxResult.success("查询成功",list) ;
        }
        else {
            return AjaxResult.error("查询失败");
        }


    }
    @ApiOperation("获取所有政审不合格信息")
//    @Log(title = "政审信息", businessType = BusinessType.)
    @GetMapping(value = "/getfailed")
    public AjaxResult selectfaile() {
        String poliCarefulState="政审不通过";
        List<Policenvo> list = poliReviewInfoMapper.selectall(poliCarefulState);
//
        if (list!=null){
            return AjaxResult.success("查询成功",list) ;
        }
        else {
            return AjaxResult.error("查询失败");
        }


    }

    @ApiOperation(value = "政审中--姓名查找")
    @PostMapping ("/find")
    //
//    三张表的数据，删除的时候，直接这三个都删除
    public AjaxResult find( @RequestParam("name")String name) {
        String poliCarefulState="政审中";
        //也可以直接从redis缓冲中去调用一个foreach循环拿到对应name的数据
        QueryWrapper<PoliReviewInfo> wrapper = new QueryWrapper();
        wrapper.eq("name",name);
        List<Policenvo> list = poliReviewInfoMapper.selectpolicenvo(name,poliCarefulState);
        if (list.size()>0){
            return AjaxResult.success("姓名查找成功",list);
        }else {
            return    AjaxResult.success("没有找到该人政审中信息");
        }

    }
    @ApiOperation(value = "政审不合格--姓名查找")
    @PostMapping ("/findfailed")
    //    三张表的数据，删除的时候，直接这三个都删除
    public AjaxResult findfailed( @RequestParam("name")String name) {
        String poliCarefulState="政审不通过";
        //也可以直接从redis缓冲中去调用一个foreach循环拿到对应name的数据
        QueryWrapper<PoliReviewInfo> wrapper = new QueryWrapper();
        wrapper.eq("name",name);
        List<Policenvo> list = poliReviewInfoMapper.selectpolicenvo(name,poliCarefulState);
        if (list.size()>0){
            return AjaxResult.success("姓名查找成功",list);
        }else {
            return    AjaxResult.success("没有找到该人政审信息");
        }

    }
    @ApiOperation(value = "政审中-判断是否政审通过")
    @PostMapping ("/judge")
    /*三张表的数据，删除的时候，直接这三个都删除*/
    public AjaxResult send( @RequestParam("poliInfoId")String id,
                            @RequestParam("poliCheckResults")String poliCheckResults) {
        PoliReviewInfo person = poliReviewInfoService.getById(id);
        person.setPoliCarefulState(poliCheckResults);
        person.setPoliCheckResults(poliCheckResults);
        QueryWrapper<PoliReviewInfo> wrapper = new QueryWrapper();
        wrapper.eq("poli_info_id",id);
        boolean b =   poliReviewInfoService.update(person,wrapper);//前新后旧
        return b ? AjaxResult.success("政审结果修改成功",person) : AjaxResult.error("政审结果修改失败");
    }

    @ApiOperation("导出所有政审中的信息")
    @GetMapping("/exportexc")
    public void export(HttpServletResponse response) {
        String poliCarefulState = "政审中";
        List<Policenvo> list = poliReviewInfoMapper.selectall(poliCarefulState);
//
        poliReviewInfoService.exportpoli(response, list, Policenvo.class,"政审中信息表");

    }
    @ApiOperation("导出所有政审不合格的信息")
    @GetMapping("/exportfailed")
    public void exportfailed(HttpServletResponse response) {
        String poliCarefulState = "政审不通过";
        List<Policenvo> list = poliReviewInfoMapper.selectall(poliCarefulState);
//
        poliReviewInfoService.exportpoli(response, list, Policenvo.class,"政审不合格信息表");

    }
/*三张表的数据，删除的时候，直接这三个都删除*/




}
